package com.pandy.juc;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @description: 读写锁
 * @author: panhong
 * @date: 2025/3/18
 */
public class Code03_ReadWriteLockDemo {

    static ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
    static Lock readLock = lock.readLock();
    static Lock writeLock = lock.writeLock();
    public static void main(String[] args) {
        readLock.lock();
        try {
            System.out.println("获取读锁");
        }finally {
            readLock.unlock();
        }

        writeLock.lock();
        try {
            System.out.println("获取写锁");
        }finally {
            writeLock.unlock();
        }
    }
}
